<html>
<head>
<link href="css/qam.css" rel="stylesheet" media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
.css_name,.css_href{color:#D1AAE5;background:#624815;padding:0 5px;}
.css_href{margin-right:10px;}
</style>
</head>
<body>

	<div style="width:960px;margin:0 auto">
		<div id="message" ></div>
		
		<HR><h3>项目管理</h3>
		<div style="padding:10px;background:#E8E8FF;margin-top:10px;">
			<form method="post" action="#" name="myform" class="myform">
				<input type="hidden" value="" name="id" />
				<label><span>项目名称：</span><input type="text" value="" name="name" /></label><BR />
				<label><span>项目说明</span><input type="text" value="" name="info" /></label><BR />
				<label><span>项目SVN</span><input type="text" value="" name="svn" /></label><BR />
				<label><span>根目录</span><select name="root_flag" onchange="root_set(this.value)"><option value="0">否</option><option value="1">是</option></select></label>非根目录的项目，需要选择父项目<BR />
				<label id="parent_label"><span>父项目</span><span id="parent_box"></span></label><BR />
				<label id="type_label"><span>项目类型</span><span id="type_box"></span></label><BR />
				<label><span>公用css</span><input type="hidden" value="" name="css_data" /><input type="hidden" value="" name="css_name" />
				<a href="#" onclick="read('css')">查看</a>
				<input type="file" id="file" size="10" multiple="true" onchange="select_css(this.files)" /><BR />
				<div id="css_data"></div>
				<input type="button" value="添加" onclick="add();" name="button"  />
			</form>
		</div>
		<form name="search_form" class="search_form">
			<label>名称<input type="text" value="" name="name" /></label>
			<label>说明<input type="text" value="" name="info" /></label>
			<label>项目SVN<input type="text" value="" name="svn" /></label>
			<label>根目录<select name="root_flag"><option value="">请选择</option><option value="0">否</option><option value="1">是</option></select></label>
			<label>父项目<span id="search_parent_box"></span></label>
			<label>项目类型<span id="search_type_box"></span></label>
			<label><input type="button" value="搜索" name="search_btn" onclick="search(0)" /></label><BR><BR>
			<label>模糊查找<input type="text" value="" name="search_data" /></label>(关键字用空格分开)
			<label><input type="button" value="搜索" name="search_btn" onclick="search(1)" /><input type="button" value="重置" name="search_btn" onclick="search_clear()" /></label>
			
		</form>
		<div style="padding:10px;background:#E8E8FF;margin-top:10px;" id="listbox"></div>
		

	</div>



</body>

<script src="js/ajax.js" type="text/javascript"></script>
<script src="js/md5.js" type="text/javascript"></script>
<script src="js/function.js" type="text/javascript"></script>
<script>


function init(){load_project_list();}

//html5 选择文件
function select_css(myFiles) {
  for (var i = 0, f; f = myFiles[i]; i++) {
    var imageReader = new FileReader();
    imageReader.onload = (function(aFile) {
      return function(e) {
        document.myform.css_data.value=e.target.result;
		document.myform.css_name.value=aFile.name;
      };
	  
    })(f);
    imageReader.readAsDataURL(f);
  }
}


function root_set(t){
	if(t*1){
		$$("parent_label").style.display="none";
		$$("type_label").style.display="none";
	}
	else{
		$$("parent_label").style.display="inline-block";
		$$("type_label").style.display="inline-block";

	}
}

var project_data;
/*加载group列表start*/
function load_project_list(){
	var _url=cgipath+"project-showlist";
	var ajax_obj=new AJAX_OBJ(_url,handle_load_project_list,handle_error,5000);
	ajax_obj.postData();
}

function handle_load_project_list(xmlHttp){
	eval("var ret_json="+xmlHttp.responseText);
	var str="<select name=\"parentid\">";
	project_data=ret_json.listdata;
	for(var i=0;i<project_data.length;i++){
		if(project_data[i].root_flag==1)//只显示父项目
			str+="<option value=\""+project_data[i].id+"\" >"+project_data[i].name+"</option>";
	}
	str+="</select>";
	$$("parent_box").innerHTML=str
	handle_load_project_list_search(xmlHttp);
}

function handle_load_project_list_search(xmlHttp){
	eval("var ret_json="+xmlHttp.responseText);
	var str="<select name=\"parentid\">";
	str+="<option value=\"\" >请选择</option>";
	project_data=ret_json.listdata;
	for(var i=0;i<project_data.length;i++){
		if(project_data[i].root_flag==1)//只显示父项目
			str+="<option value=\""+project_data[i].id+"\" >"+project_data[i].name+"</option>";
	}
	str+="</select>";
	$$("search_parent_box").innerHTML=str
	load_type_list();
}
/*加载group列表end*/

var type_data;
/*加载type列表start*/
function load_type_list(){
	var _url=cgipath+"project-typeShowlist";
	var ajax_obj=new AJAX_OBJ(_url,handle_load_type_list,handle_error,5000);
	ajax_obj.postData();
}

function handle_load_type_list(xmlHttp){
	eval("var ret_json="+xmlHttp.responseText);
	var str="<select name=\"typeid\">";
	type_data=ret_json.listdata;
	for(var i=0;i<type_data.length;i++){
			str+="<option value=\""+type_data[i].id+"\" >"+type_data[i].name+"</option>";
	}
	str+="</select>";
	$$("type_box").innerHTML=str
	handle_load_type_list_search(xmlHttp);
}

function handle_load_type_list_search(xmlHttp){
	eval("var ret_json="+xmlHttp.responseText);
	var str="<select name=\"typeid\">";
	str+="<option value=\"\" >请选择</option>";
	type_data=ret_json.listdata;
	for(var i=0;i<type_data.length;i++){
			str+="<option value=\""+type_data[i].id+"\" >"+type_data[i].name+"</option>";
	}
	str+="</select>";
	$$("search_type_box").innerHTML=str
	showlist();
}
/*加载type列表end*/

/*****project add********/
function add(){
	var _url=cgipath+"project-add";
	var ajax_obj=new AJAX_OBJ(_url,handle_add,handle_error,5000);
	ajax_obj.postData(formToString(document.myform));
}
function handle_add(xmlHttp){
	//$$("message").innerHTML=xmlHttp.responseText;return;
	eval("var ret_json="+xmlHttp.responseText);
	$$("message").innerHTML="【ret】"+ret_json.ret+"【msg】"+ret_json.msg;
	showlist();
}
/*****project getinfo********/
function edit(t){
	var _url=cgipath+"project-getinfo";
	var ajax_obj=new AJAX_OBJ(_url,handle_edit,handle_error,5000);
	ajax_obj.postData("&id="+t);
}
function handle_edit(xmlHttp){
	//$$("message").innerHTML=xmlHttp.responseText;return;
	eval("var ret_json="+xmlHttp.responseText);
	$$("message").innerHTML="【ret】"+ret_json.ret+"【msg】"+ret_json.msg;
	document.myform.id.value=ret_json.record.id;
	document.myform.name.value=ret_json.record.name;
	document.myform.svn.value=ret_json.record.svn;
	document.myform.info.value=ret_json.record.info;
	document.myform.root_flag.value=ret_json.record.root_flag;
	document.myform.typeid.value=ret_json.record.typeid;
	var str="<select name=\"parentid\">";
	for(var i=0;i<project_data.length;i++){
		str+="<option value=\""+project_data[i].id+"\"";
		if(project_data[i].id==ret_json.record.parentid)str+=" selected=\"selected\" ";
		str+=">"+project_data[i].name+"</option>";
	}
	str+="</select>";
	root_set(ret_json.record.root_flag);
	$$("parent_box").innerHTML=str
	
	var css_data="";
	for(var i=0;i<ret_json.record.css_list.length;i++){
		css_data+="<a href=\""+cgipath+ret_json.record.css_list[i].href+"\" target=\"_blank\" class=\"css_name\">"+ret_json.record.css_list[i].name+"</a><a href=\"javascript:void(0);\" onclick=\"css_del('"+ret_json.record.css_list[i].name+"')\" class=\"css_href\">删除</a>"
	}
	if(ret_json.record.root_flag==0)$$("css_data").innerHTML=css_data;
	document.myform.button.value="修改";
	document.myform.button.onclick=Function("update("+ret_json.record.id+")");
}




/*****css del********/
function css_del(t){
	var _url=cgipath+"project-cssDel";
	var ajax_obj=new AJAX_OBJ(_url,function(xmlHttp){
		//$$("message").innerHTML=xmlHttp.responseText;return;
		eval("var ret_json="+xmlHttp.responseText);
		$$("message").innerHTML="【ret】"+ret_json.ret+"【msg】"+ret_json.msg;
		edit(document.myform.id.value);
	},handle_error,5000);
	ajax_obj.postData("&id="+document.myform.id.value+"&name="+t);
}





/*****project update********/
function update(){
	var _url=cgipath+"project-update";
	var ajax_obj=new AJAX_OBJ(_url,handle_update,handle_error,5000);
	ajax_obj.postData(formToString(document.myform));
}
function handle_update(xmlHttp){
	//$$("message").innerHTML=xmlHttp.responseText;return;
	eval("var ret_json="+xmlHttp.responseText);
	$$("message").innerHTML="【ret】"+ret_json.ret+"【msg】"+ret_json.msg;
	edit(document.myform.id.value);
	showlist();
}


/*****project del********/

function del(t){
	var _url=cgipath+"project-del";
	var ajax_obj=new AJAX_OBJ(_url,handle_del,handle_error,5000);
	ajax_obj.postData("&id="+t);
}
function handle_del(xmlHttp){
	//$$("message").innerHTML=xmlHttp.responseText;return;
	eval("var ret_json="+xmlHttp.responseText);
	$$("message").innerHTML="【ret】"+ret_json.ret+"【msg】"+ret_json.msg;
	showlist();
}

/*****project list********/
var page=1;//第1页
var reqnum=10;//每页显示10条
var order="id";//排序字段
var desc="1";//反序,0或空正常排序，1反序
var page_nums=0;

/*搜索*/
var search_str="";
function search(t){
	if(t==0){
		search_str="&search_flag=0";
		search_str+=formToString(document.search_form);
	}
	else {
		search_str="&search_flag=1";
		search_str+="&search_data="+encodeURIComponent(document.search_form.search_data.value);
	}
	showlist();
}

function search_clear(){
	formReset(document.search_form);
	search_str="";
	showlist();
}

function showlist(){
	var _url=cgipath+"project-showlist";
	var ajax_obj=new AJAX_OBJ(_url,handle_showlist,handle_error,5000);
	ajax_obj.postData(search_str+"&page="+page+"&reqnum="+reqnum+"&order="+order+"&desc="+desc);
}

function handle_showlist(xmlHttp){
	//$$("message").innerHTML=xmlHttp.responseText;return;
	eval("var ret_json="+xmlHttp.responseText);
	var str="<table><thead><tr>";
	str+="<td><a href='javascript:order=\"id\";desc=bin_exchange(desc);list_page(0)'>序号</a></td>";
	str+="<td><a href='javascript:order=\"name\";desc=bin_exchange(desc);list_page(0)'>名称</a></td>";
	str+="<td><a href='javascript:order=\"type\";desc=bin_exchange(desc);list_page(0)'>项目类型</a></td>";
	str+="<td><a href='javascript:order=\"root_flag\";desc=bin_exchange(desc);list_page(0)'>根目录</a></td>";
	str+="<td><a href='javascript:order=\"parentid\";desc=bin_exchange(desc);list_page(0)'>父项目</a></td>";
	str+="<td>svn</td>";
	str+="<td><a href='javascript:order=\"author\";desc=bin_exchange(desc);list_page(0)'>作者</a></td>";
	str+="<td>说明</td>";
	str+="<td>操作</td></tr></thead>";
	for(var i=0;i<ret_json.listdata.length;i++){
		str+="<tr><td>"+((page-1)*reqnum+i+1)+"</td>";
		str+="<td><a title=\""+ret_json.listdata[i].svn+"\" style=\"cursor:pointer\">"+ret_json.listdata[i].name+"</a></td>";
		var type_str="";
		for(var j=0;j<type_data.length;j++){
			if(type_data[j].id==ret_json.listdata[i].typeid)type_str=type_data[j].name;;
		}
		str+="<td>"+type_str+"</td>";
		str+="<td>"+ret_json.listdata[i].root_flag+"</td>";
		var parent_str="";
		for(var j=0;j<project_data.length;j++){
			if(project_data[j].id==ret_json.listdata[i].parentid)parent_str=project_data[j].name;;
		}
		str+="<td>"+parent_str+"</td>";
		str+="<td>"+ret_json.listdata[i].svn+"</td>";
		str+="<td>"+ret_json.listdata[i].author+"</td>";
		str+="<td>"+ret_json.listdata[i].info+"</td>";
		str+="<td><a href='#' onclick='edit("+ret_json.listdata[i].id+")'>修改</a><a href='#' onclick='del("+ret_json.listdata[i].id+")'>删除</a></td></tr>";
	}
	page_nums=Math.ceil(ret_json.nums/reqnum);
	str+="<tr><td colspan=8>共"+ret_json.nums+"条，每页"+reqnum+"条，"+page+"/"+page_nums+"</td>";
	str+="<td><a href='#' onclick='list_page(-1)'>上一页</a><a href='#' onclick='list_page(1)'>下一页</a></td></tr>";
	str+="</table>";
	$$("listbox").innerHTML=str
}

/*列表翻页*/
function list_page(t){
	page=page-(-1)*t;
	if(page<=0)page=1;
	else if(page>page_nums) page=page_nums;
	showlist();
}

</script>
<script src="js/public.js" type="text/javascript"></script>

</html>